

project , uses(../data_output/legislators_klarner.dta)



	***********
	** FLORIDA
	** Consecutive term limites: 4 x 2-year terms.
	** First year: 2000	
	***********
	
	** Florida prep Klarner
	use ../data_output/legislators_klarner.dta, clear
	gen mergename =  regexs(1) if regexm(lower(CandName),"([a-z]+),")
	keep if state=="FL" & chamber=="house"
	keep if regexm(term, "1991|1993|1995|1997|1999|2001|2003|2005|2007|2009|2011|2013|2015")
	save ../data_output/legislators_FL_house_1991_2016.dta, replace
	
	gen year_minus0 = year	
	gen year_minus2 = year-2
	gen year_minus4 = year-4
	gen year_minus6 = year-6
	tostring year_minus*, replace
	gen s = year_minus6+";" +year_minus4+";"+year_minus2+";"+ year_minus0 + ";"
	gen termlimited = regexm(elections_won, s)==1 & year>=1998		
	save ../data_output/legislators_FL_house_1991_2016.dta, replace
project , creates(../data_output/legislators_FL_house_1991_2016.dta)

	
	
project, original(../data_input/FL/house_journals/fl_legislators_bills.csv)
	import delimited using ../data_input/FL/house_journals/fl_legislators_bills.csv, clear  delimiters(";") bindquotes(strict) encoding("utf-8")
	rename dist district
	gen term = ""
	replace term = "1991-1992" if year==1991 | year==1992 
	replace term = "1993-1994" if year==1993 | year==1994 
	replace term = "1995-1996" if year==1995 | year==1996 
	replace term = "1997-1998" if year==1997 | year==1998 
	replace term = "1999-2000" if year==1999 | year==2000 
	replace term = "2001-2002" if year==2001 | year==2002
	replace term = "2003-2004" if year==2003 | year==2004
	replace term = "2005-2006" if year==2005 | year==2006
	replace term = "2007-2008" if year==2007 | year==2008
	replace term = "2009-2010" if year==2009 | year==2010
	replace term = "2011-2012" if year==2011 | year==2012
	replace term = "2013-2014" if year==2013 | year==2014
	replace term = "2015-2016" if year==2015 | year==2016	
	drop if term==""
	replace sponsored =sponsored +  "," if regexm(sponsored, ",$")==0
	egen sponsor = noccur(sponsored) , string(",")
	gen mergename = regexs(1) if regexm(lower(name),"([a-z]+),")

	collapse  (sum) sponsor, by(mergename term dist)

	replace mergename="vanzant" if mergename=="zant" 
	replace mergename="clarkereed" if mergename=="reed" & district==92
	replace mergename="robertsburke" if mergename=="burke" & district==108
	replace mergename="lopezcantera" if mergename=="cantera" & district==113
	replace mergename="bendrossmindingall" if mergename=="mindingall" & district==109
	replace mergename="wassermanschultz" if mergename=="schultz" & district==97
	replace mergename="diazdelaportilla" if mergename=="portilla" & district==115
	replace mergename="otoole" if mergename=="toole" 
	replace mergename="rodriguezchomat" if mergename=="chomat" & district==114
	replace mergename="larosa" if mergename=="rosa" & district==42
	replace mergename="dawsonwhite" if [mergename=="dawson" | mergename=="white"] & district==93
	replace mergename="greensteinrader" if mergename=="rader" & district==78
	replace mergename="degrandy" if mergename=="grand" & [district==110  ]
	replace mergename="degrandy" if mergename=="grandy" & [district==114  ]
	replace mergename="diazbalart" if mergename=="balart" 
	replace mergename="armestogarcia" if mergename=="garcia" & district==117

		
	merge 1:1 district mergename term using ../data_output/legislators_FL_house_1991_2016
	
	//3 obs are not merging (see description above for Jan Leja, Richard Alacorn and Don Perata)
	drop if _merge==1
	replace sponsor = 0 if sponsor==.
	drop _merge termlimited year_minus* s
	save ../data_output/tot_bills_by_sponsor_FL_house_1991_2016.dta, replace
project, creates(../data_output/tot_bills_by_sponsor_FL_house_1991_2016.dta)	

	
	
	
	use ../data_output/legislators_klarner.dta, clear
	gen lastname = regexs(1) if regexm(lower(CandName),"([^,]+), [^!]")
	gen firstletter = regexs(1) if regexm(lower(CandName),"[^,]+, ([^!])")
	gen secondletter = regexs(1) if regexm(lower(CandName),"[^,]+, ([^!][^!])")
	keep if state=="FL" & chamber=="house"
	keep if regexm(term, "2003|2005|2007|2009|2011|2013|2015")
	gen os_mergename = lastname
	bys  os_mergename term: gen n = _n
	by  os_mergename term: egen mean_n=mean(n)
	replace os_mergename = lastname + " " + firstletter if mean_n>1  //firstname  + " " +  lastname //firstname+ ". "
	drop n mean_n
	tempfile tmp
	save `tmp', replace

project , original(../data_input/FL/fl_bills.csv)	
	import delimited using ../data_input/FL/fl_bills.csv,  clear  delimiters(";") bindquotes(strict) encoding("utf-8") varname(1)
	gen os_mergename = sponsor
	replace os_mergename = trim(regexr(lower(sponsor) , "\([^!]+\)", "" ))
	replace os_mergename = trim(regexs(1)) + " " + os_mergename if regexm(lower(sponsor) , "\(([^!]+)\)")
	gen inoffice = regexs(1) if regexm(session, "([0-9][0-9][0-9][0-9])")
	drop if regexm(inoffice, "1998|1999|2000|2001|2018")  //no sponsors for these years
	gen term = ""
	replace term = "2003-2004" if regexm(inoffice, "2003|2004")
	replace term = "2005-2006" if regexm(inoffice, "2005|2006")
	replace term = "2007-2008" if regexm(inoffice, "2007|2008")
	replace term = "2009-2010" if regexm(inoffice, "2009|2010")
	replace term = "2011-2012" if regexm(inoffice, "2011|2012")
	replace term = "2013-2014" if regexm(inoffice, "2013|2014")
	replace term = "2015-2016" if regexm(inoffice, "2015|2016")
	replace os_mergename = lower(os_mergename)
	replace os_mergename = subinstr(os_mergename,"’","",.)
	replace os_mergename = subinstr(os_mergename,"'","",.)
	replace os_mergename = subinstr(os_mergename,"-","",.)	
	replace os_mergename = subinstr(os_mergename,".","",.)	
	replace os_mergename = subinstr(os_mergename,"van ","van",.)	
	replace os_mergename = "davis" if os_mergename == "davis d" & regexm(term, "2002")
	replace os_mergename = "diazdelaportilla" if os_mergename == "diaz de la portilla" & regexm(term, "2002")
	replace os_mergename = "gibson" if os_mergename == "gibson h" & regexm(term, "2002")
	replace os_mergename = "gibson a" if os_mergename == "gibson" & regexm(term, "2003|2005|2007")
	replace os_mergename = "roberson" if os_mergename == "roberson y" & regexm(term, "2003|2005|2007")
	replace os_mergename = "grant" if os_mergename == "grant m" & regexm(term, "2005|2007")
	replace os_mergename = "taylor" if os_mergename == "taylor p" & regexm(term, "2005|2007")
	replace os_mergename = "williams" if os_mergename == "williams t" & regexm(term, "2005|2007")
	replace os_mergename = "coley" if os_mergename == "coley d" & regexm(term, "2005")
	replace os_mergename = "brise" if os_mergename == "bris" & regexm(term, "2007|2009")
	replace os_mergename = "garcia l" if os_mergename == "garcia" & regexm(term, "2007")
	replace os_mergename = "greensteinrader" if os_mergename == "rader" & regexm(term, "2009")
	replace os_mergename = "rehwinkelvasilinda" if os_mergename == "rehwinkel vasilinda" & regexm(term, "2009|2011|2013|2015")
	replace os_mergename = "taylor d" if os_mergename == "taylor" & regexm(term, "2009")
	replace os_mergename = "diaz" if os_mergename == "diaz j" & regexm(term, "2009|2011")
	replace os_mergename = "grant" if os_mergename == "grant j" & regexm(term, "2011|2013|2015")
	replace os_mergename = "nunez" if os_mergename == "nuez" & regexm(term, "2011|2013|2015")	
	replace os_mergename = "roberson" if os_mergename == "roberson k" & regexm(term, "2011|2013|2015")
	replace os_mergename = "thompson" if os_mergename == "thompson g" & regexm(term, "2011")	
	replace os_mergename = "jones" if os_mergename == "jones m" & regexm(term, "2011")
	replace os_mergename = "dentel" if os_mergename == "castor dentel" & regexm(term, "2013")
	replace os_mergename = "larosa" if os_mergename == "la rosa" & regexm(term, "2013|2015")
	replace os_mergename = "rodriguez" if os_mergename == "rodrguez j" & regexm(term, "2013|2015")
	replace os_mergename = "williams" if os_mergename == "williams a" & regexm(term, "2013|2015")
	replace os_mergename = "edwards" if os_mergename == "edwardswalpole" & regexm(term, "2013|2015")
	replace os_mergename = "miller" if os_mergename == "miller m" & regexm(term, "2015")
	replace os_mergename = "jones s" if os_mergename == "jones" & regexm(term, "2013|2015")
		
	merge m:1  os_mergename term  using `tmp'
	drop if _merge==1
	* 6 obs are not merging
	save ../data_output/bills_by_sponsor_FL_house_2003_2016.dta, replace
project , creates(../data_output/bills_by_sponsor_FL_house_2003_2016.dta)	
	use ../data_output/bills_by_sponsor_FL_house_2003_2016.dta, clear
	drop sponsor
	gen sponsor = 1 if bill!=""
	gen law = regexm(lower(status), "chapter|approved by gov|adopted|signed by") & regexm(lower(status), "died")==0
	collapse (sum) sponsor law (first) elections_* terms_in_office win TermLengthActual CandName district chamber state party  inoffice year  vtsh, by(CandId term )
	gen tmp = 1
	append using ../data_output/tot_bills_by_sponsor_FL_house_1991_2016.dta
	drop if tmp==. & regexm(term, "2003|2005|2007|2009|2011|2013|2015")	
	drop tmp

	gen year_minus0 = year	
	gen year_minus2 = year-2
	gen year_minus4 = year-4
	gen year_minus6 = year-6
	tostring year_minus*, replace
	gen s = year_minus6+";" +year_minus4+";"+year_minus2+";"+ year_minus0 + ";"
	gen termlimited = regexm(elections_won, s)==1 & year>=1998			
	
	
	save ../data_output/total_bills_by_sponsor_FL_house_1991_2016.dta, replace
project , creates(../data_output/total_bills_by_sponsor_FL_house_1991_2016.dta)	


		
		
	**Voting
	
	use ../data_output/legislators_klarner.dta, clear
	gen lastname = regexs(1) if regexm(lower(CandName),"([^,]+), [^!]")
	gen firstletter = regexs(1) if regexm(lower(CandName),"[^,]+, ([^!])")
	gen secondletter = regexs(1) if regexm(lower(CandName),"[^,]+, ([^!][^!])")
	keep if state=="FL" & chamber=="house"
	keep if regexm(term, "2003|2005|2007|2009|2011|2013|2015")
	gen os_mergename = lastname
	bys  os_mergename term: gen n = _n
	by  os_mergename term: egen mean_n=mean(n)
	replace os_mergename = lastname + ", " + firstletter+"." if mean_n>1  //firstname  + " " +  lastname //firstname+ ". "
	drop n mean_n
	tempfile tmp
	save `tmp', replace
	
project , original(../data_input/FL/fl_votes.csv)	
	import delimited using ../data_input/FL/fl_votes.csv,  clear  delimiters(";") bindquotes(strict) encoding("utf-8") varnames(1)
	gen floor = regexm(location, "^floor:")
	gen term = ""
	replace term = "2003-2004" if regexm(session, "2003|2004")
	replace term = "2005-2006" if regexm(session, "2005|2006")
	replace term = "2007-2008" if regexm(session, "2007|2008")
	replace term = "2009-2010" if regexm(session, "2009|2010")
	replace term = "2011-2012" if regexm(session, "2011|2012")
	replace term = "2013-2014" if regexm(session, "2013|2014")
	replace term = "2015-2016" if regexm(session, "2015|2016")
	gen os_mergename = lower(name)
	replace os_mergename = lower(os_mergename)
	replace os_mergename = subinstr(os_mergename,"’","",.)
	replace os_mergename = subinstr(os_mergename,"'","",.)
	replace os_mergename = subinstr(os_mergename,"-","",.)	
	replace os_mergename = "roberson"	if os_mergename=="roberson, y." & regexm(term, "2003|2005|2007")
	replace os_mergename = "garcia"	if os_mergename=="garcia, r." & regexm(term, "2003|2005")
	replace os_mergename = "gibson, a."	if os_mergename=="gibson" & regexm(term, "2003|2005|2007")
	replace os_mergename = "grant"	if os_mergename=="grant, m." & regexm(term, "2003|2005|2007")
	replace os_mergename = "taylor"	if os_mergename=="taylor, p." & regexm(term, "2005")
	replace os_mergename = "williams"	if os_mergename=="williams, t." & regexm(term, "2005|2007")
	replace os_mergename = "garcia"	if os_mergename=="garcia, l." & regexm(term, "2007")
	replace os_mergename = "rehwinkelvasilinda"	if os_mergename=="rehwinkel vasilinda" & regexm(term, "2009|2011|2013|2015")
	replace os_mergename = "taylor, d."	if os_mergename=="taylor" & regexm(term, "2009")
	replace os_mergename = "vanzant"	if os_mergename=="van zant" & regexm(term, "2009|2011|2013|2015")
	replace os_mergename = "jones"	if os_mergename=="jones, m." & regexm(term, "2009|2011")
	replace os_mergename = "greensteinrader"	if os_mergename=="rader" & regexm(term, "2009")
	replace os_mergename = "diaz"	if os_mergename=="diaz, j." & regexm(term, "2011")
	replace os_mergename = "grant"	if os_mergename=="grant, j." & regexm(term, "2011|2013|2015")
	replace os_mergename = "roberson"	if os_mergename=="roberson, k." & regexm(term, "2011|2013|2015")
	replace os_mergename = "thompson"	if os_mergename=="thompson, g." & regexm(term, "2011")
	replace os_mergename = "dentel"	if os_mergename=="castor dentel" & regexm(term, "2013")
	replace os_mergename = "edwards"	if os_mergename=="edwardswalpole" & regexm(term, "2013|2015")
	replace os_mergename = "jones, s."	if os_mergename=="jones" & regexm(term, "2013|2015")
	replace os_mergename = "larosa"	if os_mergename=="la rosa" & regexm(term, "2013|2015")
	replace os_mergename = "rodriguez"	if os_mergename=="rodriguez, j." & regexm(term, "2013|2015")
	replace os_mergename = "williams"	if os_mergename=="williams, a." & regexm(term, "2013|2015")
	replace os_mergename = "miller"	if os_mergename=="miller, m." & regexm(term, "2015")
			
	merge m:1  os_mergename term using `tmp'
	
	// 4 obs not merging
	drop if _merge==1
	drop _merge	
	
	replace vote = "1" if vote=="Y"
	replace vote = "-1" if vote=="N"
	replace vote = "0" if regexm(vote,"1")==0
	
	gen floorvotes = 0 if floor==1
	replace floorvotes = 1 if regexm(vote, "1")  & floor==1
	gen cmtvotes = 0 if floor==0
	replace cmtvotes = 1 if regexm(vote, "1")  & floor==0	
	destring vote, replace
	egen vote_id = group(session chamber bill date location outcome url)	, missing
	bys vote_id: egen votemargin=mean(vote)
	gen close_floorvotes = floorvotes==1 if abs(votemargin)<0.1
	bys party vote_id : egen party_mean=mean(vote)
	gen party_vote = 0
	replace party_vote = 1 if party_mean>0
	replace party_vote = -1 if party_mean<0
	gen vote_party_line = vote==party_vote
	gen vote_against_party = vote==-party_vote
	
	preserve
		save ../data_output/floorvotes_FL_2003_2016.dta, replace	
		keep if floor==1
project, creates(../data_output/floorvotes_FL_2003_2016.dta)	

		use ../data_output/floorvotes_FL_2003_2016.dta
		collapse  (mean) vote_party_line vote_against_party (sum) close_floorvotes floorvotes (first) elections_* terms_in_office win TermLengthActual CandName district chamber state party  inoffice year  vtsh, by(CandId term )	
		save ../data_output/total_floorvotes_FL_2003_2016.dta, replace
project, creates(../data_output/total_floorvotes_FL_2003_2016.dta)	
	
	restore

	
	save ../data_output/cmtvotes_FL_2003_2016.dta, replace	
project , creates(../data_output/cmtvotes_FL_2003_2016.dta)	

	use ../data_output/cmtvotes_FL_2003_2016.dta, clear
	keep if floor==0
	collapse  (mean) vote_party_line vote_against_party (sum)  cmtvotes (first) elections_* terms_in_office win TermLengthActual CandName district chamber state party  inoffice year  vtsh, by(CandId term )	
	save ../data_output/total_cmtvotes_FL_2003_2016.dta, replace	
project , creates(../data_output/total_cmtvotes_FL_2003_2016.dta)	




		
